package com.bw.day1homework

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.bw.lib_common.NavPath
import kotlinx.coroutines.delay


//@Preview(showBackground = true)
@Composable
fun SplashPage(navHostController: NavHostController) {
    var num by remember {
        mutableStateOf(2)
    }

    LaunchedEffect(key1 = "", block = {
        for (i in 1 downTo 0) {
            delay(1000)
            num = i
            if (num <= 0) {
                navHostController.navigate(NavPath.MAIN)
            }
        }
    })

    Column(
        Modifier
            .fillMaxWidth()
            .fillMaxHeight()
    ) {
        Text(
            text = "倒计时：$num 秒",
            Modifier
                .fillMaxWidth()
                .padding(top = 20.dp, end = 20.dp),
            textAlign = TextAlign.End
        )

        Image(
            painter = painterResource(id = R.drawable.logo),
            contentDescription = "",
            Modifier
                .fillMaxWidth()
                .weight(1f)
        )

        Text(
            text = "当前版本:1.0.1",
            Modifier
                .fillMaxWidth()
                .padding(bottom = 20.dp),
            textAlign = TextAlign.Center
        )

    }
}